home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_5118.txt < prev    next >
Text File  |  1991-02-27  |  3KB  |  142 lines

  1. -- card: 5118 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part 6 (field)
  9. -- low flags: 00
  10. -- high flags: 0007
  11. -- rect: left=30 top=78 right=296 bottom=478
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 4
  16. -- text size: 9
  17. -- style flags: 0
  18. -- line height: 12
  19. -- part name: 
  20.  
  21.  
  22. -- part 7 (button)
  23. -- low flags: 00
  24. -- high flags: 0001
  25. -- rect: left=13 top=29 right=57 bottom=351
  26. -- title width / last selected line: 0
  27. -- icon id / first selected line: 0 / 0
  28. -- text alignment: 1
  29. -- font id: 0
  30. -- text size: 12
  31. -- style flags: 0
  32. -- line height: 16
  33. -- part name: New Button
  34.  
  35.  
  36. -- part contents for background part 7
  37. ----- text -----
  38. 40
  39.  
  40. -- part contents for background part 29
  41. ----- text -----
  42.  
  43.  
  44.  
  45. -- part contents for card part 6
  46. ----- text -----
  47. /*
  48. *   FILE:    student.person.c
  49. *   AUTHOR:  R.G.
  50. *   CREATED: June 7, 1990
  51. *   
  52. *   Think C program illustrating derivation of the Student class
  53. *   from the Person class.
  54. *
  55. *   PROJECT CONTENTS:
  56. *   student.person.c, ANSI, oops libraries
  57. */
  58.  
  59. # include <oops.h>
  60. # include <stdio.h>
  61.  
  62. /******************************************************************
  63. *   Definition of Person class and its methods (no changes here!)
  64. ******************************************************************/
  65. struct Person:indirect
  66. {
  67.     int     age;
  68.     int     weight;
  69.  
  70.     void    set(void);
  71.     void    print(void);
  72. };
  73.  
  74. void    Person::set(void)
  75. {
  76.     int     new_age,
  77.             new_weight;
  78.  
  79.     printf("Enter age and weight separated by spaces:\n");
  80.     scanf("%d %d",&new_age,&new_weight);
  81.  
  82.     age = new_age;
  83.     weight = new_weight;
  84. }
  85.  
  86. void    Person::print(void)
  87. {
  88.     printf("My age is %d\n",age);
  89.     printf("My weight is %d\n",weight);
  90. }
  91.  
  92. /******************************************************************
  93. *   Definition of new Student class and its methods
  94. ******************************************************************/
  95. struct Student:Person
  96. {
  97.     int     id_number;
  98.  
  99.     void    set(void);
  100.     void    print(void);
  101. };
  102.  
  103. void    Student::set(void)
  104. {
  105.     int     new_id;
  106.  
  107.     printf("Enter student id number:\n");
  108.     scanf("%d",&new_id);
  109.  
  110.     id_number = new_id;
  111.  
  112.     inherited::set();
  113. }
  114.  
  115. void    Student::print(void)
  116. {
  117.     printf("My id number is %d\n",id_number);
  118.     inherited::print();
  119. }
  120.  
  121. /******************************************************************
  122. *   main() function (only one change)
  123. ******************************************************************/
  124. main()
  125. {
  126.     Person  *person;
  127.  
  128.     person = new(Student);
  129.     person->set();
  130.     person->print();
  131.     delete(person);
  132. }
  133.  
  134.  
  135.  
  136. -- part contents for background part 4
  137. ----- text -----
  138. A TC program using the Person and Student classes:
  139.  
  140. -- part contents for background part 6
  141. ----- text -----
  142. Derivation of Student class from Person class